﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AVIS.OutBound.Contents
{
    /// <summary>
    /// 首页的Banner图片
    /// </summary>
    public class Banner : BaseCMS
    {
        /// <summary>
        /// 图片或者视频文件路径
        /// </summary>
        public string FileUrl
        {
            get
            {
                if (string.IsNullOrWhiteSpace(_FileUrl))
                {
                    return _FileUrl;
                }

                if (!_FileUrl.ToLower().StartsWith("http"))
                {
                    if (Type == BannerType.Image)
                    {
                        return SiteConfig.UploadImgUrl + _FileUrl;
                    }
                    else if (Type == BannerType.Flash)
                    {
                        return SiteConfig.UploadVideoUrl + _FileUrl;
                    }
                }

                return _FileUrl;
            }
            set
            {
                _FileUrl = value.ToLower();
            }
        }
        private string _FileUrl = string.Empty;

        /// <summary>
        /// 链接地址
        /// </summary>
        public string LinkUrl { get; set; }

        /// <summary>
        /// Banner类型：图片或视频
        /// </summary>
        public BannerType Type { get; set; }

        public Banner MapFrom(ContentCacheItem c)
        {
            if (c == null)
                return this;

            base.MapFromContent(c);
            this.LinkUrl = c.Field2;
            if (!string.IsNullOrEmpty(c.Field36))
            {
                this.Type = BannerType.Image;
                this.FileUrl = c.Field36;
            }
            else if (!string.IsNullOrEmpty(c.Field51))
            {
                this.Type = BannerType.Flash;
                this.FileUrl = c.Field51;
            }

            return this;
        }
    }





}
